package org.n.shop.controller;

import lombok.AllArgsConstructor;
import org.n.shop.annotation.RequiresLogin;
import org.n.shop.domain.dto.InsertOrderDto;
import org.n.shop.domain.entity.Order;
import org.n.shop.result.RestResult;
import org.n.shop.service.OrderService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@AllArgsConstructor
public class OrderController {
    private OrderService orderService;

    @RequiresLogin
    @RequestMapping("/add")
    public RestResult add(@RequestHeader("authorization") String authorization,
                          @RequestBody List<InsertOrderDto> insertOrderDto) {
        return orderService.add(authorization, insertOrderDto);
    }

    @RequiresLogin
    @RequestMapping("/pay")
    public RestResult pay(@RequestBody Order order) {
        return orderService.pay(order.getOrderId());
    }

    @RequiresLogin
    @RequestMapping("/id")
    public RestResult selectOrderById(@RequestParam("id") int id) {
        return orderService.selectOrderById(id);
    }
}
